package reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.concurrent.Callable;

/**
 * 调用有参方法
 */
public class ReflectDemo5 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        Person p = new Person();
        p.say("大家好!");
        Class cls = Class.forName("reflect.Person");
        Object o = cls.newInstance();
        Method method = cls.getMethod("say", String.class);
        method.invoke(o, "嘿嘿");
        Method method1 = cls.getMethod("say", String.class, int.class);
        method1.invoke(o, "哈哈", 5);
    }
}
